<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class SectionsController extends ExtendedController
{
    function  __construct()
    {
        parent::__construct();
        $this->loadLibrary('Utility');
        $session = Session::getInstance();
        if ($session->get('permission') != 1)
        {
            Utility::error('Bạn không có quyền truy cập chức năng này !', 'index');
        }
    }

    public function index($subjectId = NULL)
    {
        if (isset($_POST['actiontype']))
        {
            switch ($_POST['actiontype'])
            {
                case 'add':
                    $subjectid = $_POST['subjectList'];
                    $name = $_POST['name'];
                    $weight = $_POST['weight'];
                    $this->loadModel('sections');
                    $this->models['sections']->add($subjectid, $name, $weight);
                    break;

                case 'edit':
                    $this->loadModel('sections');
                    $this->models['sections']->edit($_POST['itemid'], $_POST['name'], $_POST['weight']);
                    break;

                case 'remove':
                    $id = $_POST['itemid'];
                    $this->loadModel('sections');
                    $this->models['sections']->remove($id);
                    break;
            }
        }
        $session = Session::getInstance();
        $this->loadModel('sections');
        $data = $this->models['sections']->getSections($subjectId);
        if ($data == FALSE)
        {
            Utility::error('Có lỗi xảy ra !', 'index');
            exit();
        }
        //        var_dump($data);exit();
        $this->loadView('sections');
        $this->views['sections']->setBlockData($data);
        $this->views['sections']->render();

    }

}

?>
